from waftools.pebble_test import clar


def _test_bluetooth_persistent_storage(bld, version=1):
    test_name = "test_bluetooth_persistent_storage_v%u" % version
    version_override_include = 'bluetooth_persistent_storage_v%u' % version
    clar(bld,
         sources_ant_glob=(
            "src/fw/services/normal/bluetooth/bluetooth_persistent_storage.c "
           "src/fw/services/normal/settings/settings_file.c "
           "src/fw/services/normal/settings/settings_raw_iter.c "
           "src/fw/services/normal/filesystem/pfs.c "
           "src/fw/services/normal/filesystem/flash_translation.c "
           "src/fw/flash_region/flash_region.c "
           "src/fw/flash_region/filesystem_regions.c "
           "src/fw/util/crc8.c "
           "src/fw/util/legacy_checksum.c "
           "src/fw/system/hexdump.c "
           "tests/fakes/fake_shared_prf_storage.c "
           "tests/fakes/fake_events.c "
           "tests/fakes/fake_spi_flash.c "
           "tests/fakes/fake_rtc.c "
         ),
         test_sources_ant_glob="test_bluetooth_persistent_storage.c",
         test_name=test_name,
         override_includes=['dummy_board', version_override_include])


def build(bld):
    clar(bld,
         sources_ant_glob=(
          "src/fw/services/normal/bluetooth/ble_hrm.c "
          "tests/fakes/fake_events.c "
         ),
         test_sources_ant_glob="test_ble_hrm.c",
         defines=['CAPABILITY_HAS_BUILTIN_HRM=1'])

    clar(bld,
         sources_ant_glob=(
            "src/fw/services/common/bluetooth/local_addr.c"
         ),
         test_sources_ant_glob="test_local_addr.c")

    clar(bld,
         sources_ant_glob=(
            "src/fw/services/prf/bluetooth/bluetooth_persistent_storage.c "
            "src/fw/services/common/shared_prf_storage/v2_sprf/shared_prf_storage.c "
            "tests/fakes/fake_spi_flash.c "
            "tests/fakes/fake_events.c "
         ),
         test_sources_ant_glob="test_bluetooth_persistent_storage_prf.c",
         override_includes=['snowy_mfg_board'])

    # Run the bluetooth_persistent_storage.c unit tests
    # for the v1 and v2 serialization formats:
    _test_bluetooth_persistent_storage(bld, version=1)
    _test_bluetooth_persistent_storage(bld, version=2)


# vim:filetype=python
